/*
 * Copyright (c) 2025-2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * @file hks_type_error_code.h
 *
 * @brief Declares huks error code.
 *
 * @since 8
 */

#ifndef HKS_ERROR_CODE_H
#define HKS_ERROR_CODE_H

#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
 * @brief hks error code
 */
 enum HksErrorCode {
    HKS_SUCCESS = 0,
    HKS_FAILURE = -1,
    HKS_ERROR_BAD_STATE = -2,
    HKS_ERROR_INVALID_ARGUMENT = -3,
    HKS_ERROR_NOT_SUPPORTED = -4,
    HKS_ERROR_NO_PERMISSION = -5,
    HKS_ERROR_INSUFFICIENT_DATA = -6,
    HKS_ERROR_BUFFER_TOO_SMALL = -7,
    HKS_ERROR_INSUFFICIENT_MEMORY = -8,
    HKS_ERROR_COMMUNICATION_FAILURE = -9,
    HKS_ERROR_STORAGE_FAILURE = -10,
    HKS_ERROR_HARDWARE_FAILURE = -11,
    HKS_ERROR_ALREADY_EXISTS = -12,
    HKS_ERROR_NOT_EXIST = -13,
    HKS_ERROR_NULL_POINTER = -14,
    HKS_ERROR_FILE_SIZE_FAIL = -15,
    HKS_ERROR_READ_FILE_FAIL = -16,
    HKS_ERROR_INVALID_PUBLIC_KEY = -17,
    HKS_ERROR_INVALID_PRIVATE_KEY = -18,
    HKS_ERROR_INVALID_KEY_INFO = -19,
    HKS_ERROR_HASH_NOT_EQUAL = -20,
    HKS_ERROR_MALLOC_FAIL = -21,
    HKS_ERROR_WRITE_FILE_FAIL = -22,
    HKS_ERROR_REMOVE_FILE_FAIL = -23,
    HKS_ERROR_OPEN_FILE_FAIL = -24,
    HKS_ERROR_CLOSE_FILE_FAIL = -25,
    HKS_ERROR_MAKE_DIR_FAIL = -26,
    HKS_ERROR_INVALID_KEY_FILE = -27,
    HKS_ERROR_IPC_MSG_FAIL = -28,
    HKS_ERROR_REQUEST_OVERFLOWS = -29,
    HKS_ERROR_PARAM_NOT_EXIST = -30,
    HKS_ERROR_CRYPTO_ENGINE_ERROR = -31,
    HKS_ERROR_COMMUNICATION_TIMEOUT = -32,
    HKS_ERROR_IPC_INIT_FAIL = -33,
    HKS_ERROR_IPC_DLOPEN_FAIL = -34,
    HKS_ERROR_EFUSE_READ_FAIL = -35,
    HKS_ERROR_NEW_ROOT_KEY_MATERIAL_EXIST = -36,
    HKS_ERROR_UPDATE_ROOT_KEY_MATERIAL_FAIL = -37,
    HKS_ERROR_VERIFICATION_FAILED = -38,
    HKS_ERROR_SESSION_REACHED_LIMIT = -39,

    HKS_ERROR_GET_USERIAM_SECINFO_FAILED = -40,
    HKS_ERROR_GET_USERIAM_AUTHINFO_FAILED = -41,
    HKS_ERROR_USER_AUTH_TYPE_NOT_SUPPORT = -42,
    HKS_ERROR_KEY_AUTH_FAILED = -43,
    HKS_ERROR_DEVICE_NO_CREDENTIAL = -44,
    HKS_ERROR_API_NOT_SUPPORTED = -45,
    HKS_ERROR_KEY_AUTH_PERMANENTLY_INVALIDATED = -46,
    HKS_ERROR_KEY_AUTH_VERIFY_FAILED = -47,
    HKS_ERROR_KEY_AUTH_TIME_OUT = -48,

    HKS_ERROR_CREDENTIAL_NOT_EXIST = -49,

    HKS_ERROR_CHECK_GET_ALG_FAIL = -100,
    HKS_ERROR_CHECK_GET_KEY_SIZE_FAIL = -101,
    HKS_ERROR_CHECK_GET_PADDING_FAIL = -102,
    HKS_ERROR_CHECK_GET_PURPOSE_FAIL = -103,
    HKS_ERROR_CHECK_GET_DIGEST_FAIL = -104,
    HKS_ERROR_CHECK_GET_MODE_FAIL = -105,
    HKS_ERROR_CHECK_GET_NONCE_FAIL = -106,
    HKS_ERROR_CHECK_GET_AAD_FAIL = -107,
    HKS_ERROR_CHECK_GET_IV_FAIL = -108,
    HKS_ERROR_CHECK_GET_AE_TAG_FAIL = -109,
    HKS_ERROR_CHECK_GET_SALT_FAIL = -110,
    HKS_ERROR_CHECK_GET_ITERATION_FAIL = -111,
    HKS_ERROR_INVALID_ALGORITHM = -112,
    HKS_ERROR_INVALID_KEY_SIZE = -113,
    HKS_ERROR_INVALID_PADDING = -114,
    HKS_ERROR_INVALID_PURPOSE = -115,
    HKS_ERROR_INVALID_MODE = -116,
    HKS_ERROR_INVALID_DIGEST =  -117,
    HKS_ERROR_INVALID_SIGNATURE_SIZE = -118,
    HKS_ERROR_INVALID_IV = -119,
    HKS_ERROR_INVALID_AAD = -120,
    HKS_ERROR_INVALID_NONCE = -121,
    HKS_ERROR_INVALID_AE_TAG = -122,
    HKS_ERROR_INVALID_SALT = -123,
    HKS_ERROR_INVALID_ITERATION = -124,
    HKS_ERROR_INVALID_OPERATION = -125,
    HKS_ERROR_INVALID_WRAPPED_FORMAT = -126,
    HKS_ERROR_INVALID_USAGE_OF_KEY = -127,
    HKS_ERROR_CHECK_GET_AUTH_TYP_FAILED = -128,
    HKS_ERROR_CHECK_GET_CHALLENGE_TYPE_FAILED = -129,
    HKS_ERROR_CHECK_GET_ACCESS_TYPE_FAILED = -130,
    HKS_ERROR_CHECK_GET_AUTH_TOKEN_FAILED = -131,
    HKS_ERROR_INVALID_TIME_OUT = -132,
    HKS_ERROR_INVALID_AUTH_TYPE = -133,
    HKS_ERROR_INVALID_CHALLENGE_TYPE = -134,
    HKS_ERROR_INVALID_ACCESS_TYPE = -135,
    HKS_ERROR_INVALID_AUTH_TOKEN = -136,
    HKS_ERROR_INVALID_SECURE_SIGN_TYPE = -137,
    HKS_ERROR_NEED_SKIP_ACCESS_CONTROL = -138,
    HKS_ERROR_DEVICE_PASSWORD_UNSET = -139,
    HKS_ERROR_NOT_SYSTEM_APP = -140,
    HKS_ERROR_EXCEED_LIMIT = -141,
    HKS_ERROR_UPGRADE_FAIL = -142,
    HKS_ERROR_INVALID_ACCOUNT_INFO = -143,
    HKS_ERROR_CORRUPT_FILE = -144,
    HKS_ERROR_KEY_NODE_NOT_FOUND = -145,
    HKS_ERROR_KEY_NODE_IN_USE = -146,
    HKS_ERROR_RETRYABLE_ERROR = -147,
    HKS_ERROR_TRUST_RING_DECRYPT_FAILED = -148,
    HKS_ERROR_KEY_CLEAR_FAILED = -149,
    HKS_ERROR_KEY_CONFLICT = -150,
    HKS_ERROR_EMPTY_BASE64_STRING = -151,
    HKS_ERROR_ACCESS_OTHER_USER_KEY = -152,

    HKS_ERROR_INVALID_KEY_WRAP_TYPE = -153,
    HKS_ERROR_GENERATE_SHARE_KEY = -154,
    HKS_ERROR_DSTB_PRE_ATTESTATION = -155,
    HKS_ERROR_KEY_NOT_ALLOW_WRAP = -156,
    HKS_ERROR_CHECK_WRAP_DATA_STORAGE_LEVEL = -157,
    HKS_ERROR_CHECK_WRAP_DATA_IS_PASSWORD_SET = -158,
    HKS_ERROR_CHECK_WRAP_DATA_KEY_ACCESS_TYPE = -159,
    HKS_ERROR_WRAP_KEY_BY_SHARE_KEY_VERSION_MISMATCH = -160,
    HKS_ERROR_INVALID_DATA_WRAP_TYPE = -161,
    HKS_ERROR_ASSET_KEY_NOT_FOUND = -162,
    HKS_ERROR_PARCEL_WRITE_FAIL = -163,
    HKS_ERROR_PARCEL_READ_FAIL = -164,
    HKS_ERROR_PARCEL_GET_FAIL = -165,
    HKS_ERROR_PARSE_OLD_AAD = -166,
    HKS_ERROR_CODE_KEY_ALREADY_EXIST = -167,
    HKS_ERROR_VECTOR_PUSH_BACK = -168,
    HKS_ERROR_GET_ENGINE_ATTRIBUTE_FAIL = -169,
    HKS_ERROR_GET_ENGINE_PARAM_FAIL = -170,
    HKS_ERROR_KEYSTORE_DEL_JSON = -171,
    HKS_ERROR_KEYSTORE_DEL_DB = -172,
    HKS_ERROR_KEYSTORE_USERID_MAP_EMPTY = -173,
    HKS_ERROR_KEYSTORE_USERID_NOT_FOUND = -174,
    HKS_ERROR_KEYSTORE_OLD_BUNDLENAME_NOT_FOUND = -175,
    HKS_ERROR_KEYSTORE_OLD_APPUID_NOT_FOUND = -176,
    HKS_ERROR_KEYSTORE_DB_QUERY_FAILED = -177,
    HKS_ERROR_KEYSTORE_DB_QUERY_NOT_FOUND = -178,
    HKS_ERROR_KEYSTORE_DB_QUERY_WRONG_SIZE = -179,
    HKS_ERROR_CHECK_USER_ID_FAIL = -180,
    HKS_ERROR_CODE_AEAD_TAG_LEN_INVALID = -181,
    HKS_ERROR_CODE_AEAD_TAG_LEN_NOT_EQUAL = -182,
    HKS_ERROR_INVALID_ACCESS_GROUP = -183,
    HKS_ERROR_INVALID_DEVELOPER_ID = -184,

    HKS_ERROR_LIB_REPEAT_CLOSE = -298,
    HKS_ERROR_ABILITY_MGR_CONNECT_FAIL = -299,
    HKS_ERROR_DLCLOSE_FAIL = -300,
    HKS_ERROR_OPEN_LIB_FAIL = -301,
    HKS_ERROR_FIND_FUNC_MAP_FAIL = -302,
    HKS_ERROR_GET_FUNC_POINTER_FAIL = -303,
    HKS_ERROR_CONNECT_TIME_OUT = -304,
    HKS_ERROR_LOAD_PLUGINS_FAIL = -305,
    HKS_ERROR_EXEC_FUNC_FAIL = -306,
    HKS_ERROR_CONNECT_FAIL = -307,
    HKS_ERROR_CLOSE_PROVIDER_FAIL = -308,
    HKS_ERROR_COPY_FAIL = -309,
    
    HKS_ERROR_NULL_JSON = -310,
    HKS_ERROR_JSON_NOT_STRING = -311,
    HKS_ERROR_JSON_NOT_NUMBER = -312,
    HKS_ERROR_JSON_NOT_BOOL = -313,
    HKS_ERROR_JSON_NOT_OBJECT = -314,
    HKS_ERROR_JSON_KEY_NOT_FOUND = -315,
    HKS_ERROR_JSON_NOT_ARRAY = -316,
    HKS_ERROR_JSON_PARSE_ERROR = -317,
    HKS_ERROR_JSON_ARRAY_INDEX_OUT_OF_BOUNDS = -318,
    HKS_JSON_INVAILD = -319,
    HKS_COMM_BASE64_SIZE_ERROR = -320,
    HKS_COMM_BASE64_CHAR_INVAILD = -321,
    HKS_COMM_BASE64_PADDING_INVAILD = -322,
    HKS_ERROR_JSON_PARSE_FAILED = -323,
    HKS_ERROR_JSON_MISSING_KEY = -325,
    HKS_ERROR_JSON_TYPE_MISMATCH = -326,
    HKS_ERROR_JSON_INVALID_VALUE = -327,
    HKS_ERROR_JSON_SERIALIZE_FAILED = -328,
    HKS_ERROR_REMOTE_HANDLE_NOT_FOUND = -330,
    HKS_ERROR_REMOTE_PROVIDER_MISMATCH = -331,
    HKS_ERROR_REMOTE_PROXY_GET_FAILED = -332,
    HKS_ERROR_REMOTE_OPERATION_FAILED = -333,
    HKS_ERROR_HANDLE_INSERT_ERROR = -334,

    HKS_ERROR_GEN_RANDOM_FAIL = -401,
    HKS_ERROR_UKY_INIT_SESSION_FAIL = -402,
    HKS_ERROR_UKY_UPDATE_SESSION_FAIL = -403,
    HKS_ERROR_UKY_FINISH_SESSION_FAIL = -404,
    HKS_ERROR_UKY_FIND_SESSION_HANDLE_FAIL = -405,
    HKS_ERROR_PIN_NO_AUTH = -406,

    HKS_ERROR_PROVIDER_HAS_REGISTERED = -410,
    HKS_ERROR_PROVIDER_ABILITY_NAME_NOT_EXIST = -411,
    HKS_ERROR_PROVIDER_NOT_FOUND = -412,
    HKS_ERROR_PROVIDER_IN_USE = -413,

    HKS_ERROR_UKY_PROVIDER_MGR_REGESTER_REACH_MAX_NUM = -421,

    HKS_ERROR_EXT_UNDEFINED_OPERATION = -500,
    HKS_ERROR_EXT_CREATE_VALUE_FAILED = -501,
    HKS_ERROR_EXT_GET_VALUE_FAILED = -502,
    HKS_ERROR_EXT_SET_NAME_PROPERTY_FAILED = -503,
    HKS_ERROR_EXT_GET_NAME_PROPERTY_FAILED = -504,
    HKS_ERROR_EXT_TAG_UNDEFINED = -505,
    HKS_ERROR_EXT_BASE64_FAILED = -506,
    HKS_ERROR_EXT_NULLPTR = -507,
    HKS_ERROR_EXT_CALL_FUNCTION_FAILED = -508,
    HKS_ERROR_EXT_PARSE_FUNC_FAILED = -509,
    HKS_ERROR_EXT_SEND_EVENT_FAILED = -510,
    HKS_ERROR_EXT_IS_NOT_PROMISE = -511,
    HKS_ERROR_EXT_THEN_IS_NOT_CALLABLE = -512,
    HKS_ERROR_EXT_CREATE_FUNCTION_FAILED = -513,
    HKS_ERROR_EXT_GET_CALLBACK_FAILED = -514,
    HKS_ERROR_EXT_EXCEED_MAX_SIZE = -515,
    HKS_ERROR_EXT_CALL_JS_TIME_OUT = -516,
    HKS_ERROR_EXT_JS_METHON_ERROR = -517,
    HKS_ERROR_EXT_RETURN_VALUE_INCRECT = -518,

    HKS_ERROR_ENVELOP_BUILD_RSA_ECC_SM2_MATERIAL_FAIL = -520,
    HKS_ERROR_ENVELOP_BUILD_DH_22519_MATERIAL_FAIL = -521,

    HKS_ERROR_NEW_INVALID_ARGUMENT = -997,
    HKS_ERROR_LOAD_PLUGIN_FAIL = -998,
    HKS_ERROR_INTERNAL_ERROR = -999,
    HKS_ERROR_UNKNOWN_ERROR = -1000,
};

/**
 * @brief hks err code
 */
enum HksErrCode {
    HUKS_ERR_CODE_PERMISSION_FAIL = 201,
    HUKS_ERR_CODE_NOT_SYSTEM_APP = 202,
    HUKS_ERR_CODE_ILLEGAL_ARGUMENT = 401,
    HUKS_ERR_CODE_NOT_SUPPORTED_API = 801,

    HUKS_ERR_CODE_FEATURE_NOT_SUPPORTED = 12000001,
    HUKS_ERR_CODE_MISSING_CRYPTO_ALG_ARGUMENT = 12000002,
    HUKS_ERR_CODE_INVALID_CRYPTO_ALG_ARGUMENT = 12000003,
    HUKS_ERR_CODE_FILE_OPERATION_FAIL = 12000004,
    HUKS_ERR_CODE_COMMUNICATION_FAIL = 12000005,
    HUKS_ERR_CODE_CRYPTO_FAIL = 12000006,
    HUKS_ERR_CODE_KEY_AUTH_PERMANENTLY_INVALIDATED = 12000007,
    HUKS_ERR_CODE_KEY_AUTH_VERIFY_FAILED = 12000008,
    HUKS_ERR_CODE_KEY_AUTH_TIME_OUT = 12000009,
    HUKS_ERR_CODE_SESSION_LIMIT = 12000010,
    HUKS_ERR_CODE_ITEM_NOT_EXIST = 12000011,
    HUKS_ERR_CODE_EXTERNAL_ERROR = 12000012,
    HUKS_ERR_CODE_CREDENTIAL_NOT_EXIST = 12000013,
    HUKS_ERR_CODE_INSUFFICIENT_MEMORY = 12000014,
    HUKS_ERR_CODE_CALL_SERVICE_FAILED = 12000015,
    HUKS_ERR_CODE_DEVICE_PASSWORD_UNSET = 12000016,
    HUKS_ERR_CODE_KEY_ALREADY_EXIST = 12000017,
    HUKS_ERR_CODE_INVALID_ARGUMENT = 12000018,
    HUKS_ERR_CODE_ITEM_EXISTS = 12000019,
    HUKS_ERR_CODE_DEPENDENT_MODULES_ERROR = 12000020,
    HUKS_ERR_CODE_PIN_LOCKED = 12000021,
    HUKS_ERR_CODE_PIN_CODE_ERROR = 12000022,
    HUKS_ERR_CODE_PIN_NO_AUTH = 12000023,
    HUKS_ERR_CODE_BUSY = 12000024,
    HUKS_ERR_CODE_EXCEED_LIMIT = 12000025,
};

#ifdef __cplusplus
}
#endif

#endif /* HKS_ERROR_CODE_H */
